package com.study.lxy.springcloud.common.utils.servlet;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;

public class MyHttpServletResponseWrapper extends HttpServletResponseWrapper {

    private  volatile MonitorOutoutStream mos;

    public MyHttpServletResponseWrapper(HttpServletResponse response) {
        super(response);
    }


    @Override
    public ServletOutputStream getOutputStream() throws IOException {
        if(mos==null){
            synchronized (this) {
                if(mos==null){
                    mos = new  MonitorOutoutStream(super.getOutputStream());
                }
            }
        }
        return mos;
    }

    public String getResponseBody() {
        return new String(mos.getWroteInfo());
    }

}
